#include "stdafx.h"
#include "DistributeService.h"

typedef LONG NTSTATUS;
typedef NTSTATUS (WINAPI *LPSTART_RPC_SERVER) (RPC_WSTR, RPC_IF_HANDLE);
typedef NTSTATUS (WINAPI *LPSTOP_RPC_SERVER) (RPC_IF_HANDLE);
typedef NTSTATUS (WINAPI *LPSTOP_RPC_SERVER_EX) (RPC_IF_HANDLE);

typedef VOID (WINAPI *LPNET_BIOS_OPEN) (VOID);
typedef VOID (WINAPI *LPNET_BIOS_CLOSE) (VOID);
typedef DWORD (WINAPI *LPNET_BIOS_RESET) (UCHAR);

typedef DWORD (WINAPI *LPREGISTER_STOP_CALLBACK) (HANDLE *, PCWSTR, HANDLE, WAITORTIMERCALLBACK, PVOID, DWORD);


typedef struct _SVCHOST_GLOBAL_DATA {
    PSID NullSid;                               // S-1-0-0
    PSID WorldSid;                              // S-1-1-0
    PSID LocalSid;                              // S-1-2-0
    PSID NetworkSid;                            // S-1-5-2
    PSID LocalSystemSid;                        // S-1-5-18
    PSID LocalServiceSid;                       // S-1-5-19
    PSID NetworkServiceSid;                     // S-1-5-20
    PSID BuiltinDomainSid;                      // S-1-5-32
    PSID AuthenticatedUserSid;                  // S-1-5-11
    PSID AnonymousLogonSid;                     // S-1-5-7
    PSID AliasAdminsSid;                        // S-1-5-32-544
    PSID AliasUsersSid;                         // S-1-5-32-545
    PSID AliasGuestsSid;                        // S-1-5-32-546
    PSID AliasPowerUsersSid;                    // S-1-5-32-547
    PSID AliasAccountOpsSid;                    // S-1-5-32-548
    PSID AliasSystemOpsSid;                     // S-1-5-32-549
    PSID AliasPrintOpsSid;                      // S-1-5-32-550
    PSID AliasBackupOpsSid;                     // S-1-5-32-551
    LPSTART_RPC_SERVER StartRpcServer;
    LPSTOP_RPC_SERVER StopRpcServer;
    LPSTOP_RPC_SERVER_EX StopRpcServerEx;
    LPNET_BIOS_OPEN NetBiosOpen;
    LPNET_BIOS_CLOSE NetBiosClose;
    LPNET_BIOS_RESET NetBiosReset;
    #if ((_WIN32_WINNT == _WIN32_WINNT_WINXP && NTDDI_VERSION >= NTDDI_WINXPSP2) \
        || (_WIN32_WINNT == _WIN32_WINNT_WS03 && NTDDI_VERSION >= NTDDI_WS03SP1) \
        || (_WIN32_WINNT >= _WIN32_WINNT_LONGHORN))
    LPREGISTER_STOP_CALLBACK RegisterStopCallback;
    #endif
} SVCHOST_GLOBAL_DATA;


 BOOL WINAPI Install();
 BOOL WINAPI IsInstalled();
 BOOL WINAPI Uninstall();
 BOOL WINAPI SetupParameters();
 BOOL WINAPI AddServiceToSvchost();
 VOID WINAPI Handler(DWORD dwOpcode);
 VOID WINAPI SvchostPushServiceGlobals (SVCHOST_GLOBAL_DATA *lpGlobalData); 
 VOID WINAPI ServiceMain (DWORD dwArgc, LPWSTR *lpszArgv); 